<template>
  <a-button
    type="link"
    style="padding: 4px 6px"
    @click="onClick"
    :disabled="props.data.isDefaultPwd === 1"
  >
    密码重置
  </a-button>
</template>
<script setup>
import { resetPassword } from '@/api/pw.js'
import { message } from 'ant-design-vue'
import { useDataSourceManager } from './provide-context.js'

/**
 * 全局数据
 */
let { update } = useDataSourceManager()

/**
 * 外部参数
 */
let props = defineProps({
  data: { type: Object, required: true },
})

/**
 * 编辑操作
 */
async function onClick() {
  try {
    await resetPassword(props.data.userId)
    await update()
    message.success('密码重置成功')
  } catch (e) {
    message.error('密码重置失败')
  }
}
</script>
